﻿@model PagedList.IPagedList<Data.Models.ActualGoodInStock>
@using PagedList.Mvc;
@{
    //ViewBag.Title = "Quản lý danh sách liên lạc";
    //Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
    $(document).ready(function () {
        $("#btnAddNew").click(function (e) {
            $('#CheckValid').bootstrapValidator('resetForm', true);

            $('#ID').val('0');
            $('#InputPrice').val('');
            $('#InputQuantity').val('');
            $('#OutputQuantity').val('');
            $('#InputQuantity').val('');
            $('#RemainQuantity').val('0');
            $('#GoodID').val('0');
            $('#StockID').val('0');
            $('#UOMID').val('0');
           
            $("#myModal").modal('show');
        });
        $('#cbCheckAll').change(function () {
            if (this.checked == true) {
                $('.cbCheck').prop('checked', true);
            }
            else {
                $('.cbCheck').prop('checked', false);
            }

        });
        //Su kien delete
        $("#btnDelete").click(function (e) {
            var ID = [];
            $('.table tbody input:checkbox:checked').each(function () {
                ID.push($(this).val());
            });
            if (ID.length > 0) {
                $.ajax({
                    type: "POST",
                    url: '@Url.Action("RemoveItems", "ActualGoodInStock")',
                    async: false,
                    cache: false,
                    traditional: true,
                    data: { ProID: ID },
                    success: function (result) {
                        $("#divList").html(result);

                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert(xhr.status);
                        alert(xhr.responseText);
                        alert(thrownError);
                    }
                });
            }
            else {
                alert("Bạn chưa chọn đối tượng để xóa");
            }

        });
        //Het su kien delete

        //Sự kiên search
        $("#btnSearch").click(function (e) {
            $.ajax({
                type: "GET",
                url: '@Url.Action("Search", "ActualGoodInStock")',
                async: false,
                cache: false,
                data: { Name: $('#searchString').val() },
                success: function (result) {
                    $("#divList").html(result);
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(xhr.responseText);
                    alert(thrownError);
                }
            });
        });
    });
    
    function ViewActualGoodInStock(id) {
        $('#CheckValid').bootstrapValidator('resetForm', true);
        $.ajax({
            type: "Get",
            url: '@Url.Action("Get", "ActualGoodInStock")',
            async: false,
            cache: false,
            data: { ID: id },
            // optional data          
            success: function (result) {
                $('#ID').val(result.ID);
                $('#InputPrice').val(result.InputPrice);
                $('#InputQuantity').val(result.InputQuantity);
                $('#OutputQuantity').val(result.OutputQuantity);
                $('#InputQuantity').val(result.InputQuantity);
                $('#RemainQuantity').val(result.RemainQuantity);
                $('#GoodID').val(result.GoodID);
                $('#StockID').val(result.StockID);
                $('#UOMID').val(result.UOMID);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(xhr.responseText);
                alert(thrownError);
            }
        });
        $("#myModal").modal('show');
    };

</script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#CheckValid').bootstrapValidator({
            message: 'This value is not valid',
            excluded: [':disabled'],
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                CompanyID: {
                    validators: {
                        notEmpty: {
                            message: 'Tên không để trống'
                        }
                    }
                },
                Code: {
                    validators: {
                        notEmpty: {
                            message: 'Tên không để trống'
                        }
                    }
                }
            }
        }).on('success.form.bv', function (e) {
            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);

            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');

            // Use Ajax to submit form data
            $.ajax({
                type: "POST",
                url: '@Url.Action("Save", "ActualGoodInStock")',
                async: false,
                cache: false,
                data: $('#CheckValid').serialize(),
                success: function (result) {
                    $("#myModal").modal('hide');
                    $("#divList").html(result);
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(xhr.responseText);
                    alert(thrownError);
                }
            });
        });
    });
</script>
<div id="con_form">
    <div class="container">
        <div class="c_container">
            <div class="Error"></div>
            <div>
                <input type="button" id="btnAddNew" style="margin-top: 10px;" class="btn btn-defaultxero" value="Thêm ">
                <input type="button" id="btnDelete" style="margin-top: 10px;" class="btn btn-defaultxero" value="Xóa ">
                <div style="float: right;">
                    <form action="/ActualGoodInStock" method="get" style="margin: 10px !important;">
                        <input class="form-control" id="searchString" name="searchString" placeholder="Nhập thông tin tìm kiếm" style="margin-top: 2px; margin-right: 10px;" type="text" value="">
                        <input type="button" id="btnSearch" value="Search" class="btn btn-defaultxero">
                    </form>
                </div>
            </div>
            <br>
            <div id="dialog"></div>
            <div id="confirmDel" title="Confirm!" style="background: white"></div>
            <div id="Inform" title="Inform" style="background: white"></div>
            <div id="divList">
                @{Html.RenderPartial("_ActualGoodInStockList", Model);}
            </div>
        </div>
    </div>
</div>
@{Html.RenderPartial("_Create");}